// 导入axios库
import request from '../utils/request';

// 服务器地址
import host_config from './service';
const HOST_URL = host_config.url;

// 管理员部分
// 注册接口
export const registerAPI = (data={})=> {
    return request.post(`${HOST_URL}/api/admin/register`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}
// 登录接口
export const loginAPI = (data={})=> {
    return request.post(`${HOST_URL}/api/admin/login`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}
// 找回密码
export const findpwdAPI = (data={})=> {
    return request.post(`${HOST_URL}/api/admin/findpwd`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}

// 发送邮箱验证码
export const sendEmailApi = (data={})=> {
    return request.get(`${HOST_URL}/api/email/send`, {params: data})
    .then(response=>response.data)
}
// 校验邮箱验证码
export const verifyEmailApi = (data={})=> {
    return request.get(`${HOST_URL}/api/email/verify`, {params: data})
    .then(response=>response.data)
}
// 删除邮箱验证码
export const removeEmailApi = (data={})=> {
    return request.get(`${HOST_URL}/api/email/remove`, {params: data})
    .then(response=>response.data)
}

// 删除图片
export const removePhotoApi = (data={})=> {
    return request.post(`${HOST_URL}/api/photo/remove`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}

// 发布轮播图
export const addBannerApi = (data={})=> {
    return request.post(`${HOST_URL}/api/banner/add`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}

// 获取轮播图列表
export const bannerListApi = (data={})=> {
    return request.get(`${HOST_URL}/api/banner/list`, {params: data})
    .then(response=>response.data)
}

// 删除轮播图记录
export const removeBannerApi = (data={})=> {
    return request.post(`${HOST_URL}/api/banner/remove`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}

// 上传图片（本地预览，点击发布才调用）
export const imagePreviewApi = (data={})=> {
    return request.post(`${HOST_URL}/api/photo/preview`, data, 
    {headers: {"Content-Type":"multipart/form-data"}})
    .then(response=>response.data)
}

// 添加分类
export const addClassifyApi = (data={})=> {
    return request.post(`${HOST_URL}/api/classify/add`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}
// 分类列表
export const listClassifyApi = (data={})=> {
    return request.get(`${HOST_URL}/api/classify/list`, {params: data})
    .then(response=>response.data)
}
// 删除分类
export const removeClassifyApi = (data={})=> {
    return request.post(`${HOST_URL}/api/classify/remove`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}
// 设置分类小图标
export const iconClassifyApi = (data={})=> {
    return request.post(`${HOST_URL}/api/classify/icon`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}

// 用户部分
// 用户列表
export const listUserApi = (data={})=> {
    return request.get(`${HOST_URL}/api/admin/list_user`, {params: data})
    .then(response=>response.data)
}
// 删除用户
export const removeUserApi = (data={})=> {
    return request.post(`${HOST_URL}/api/admin/remove_user`, data, {headers: {"Content-Type":"application/x-www-form-urlencoded"}})
    .then(response=>response.data)
}
// 搜索用户
export const searchUserApi = (data={})=> {
    return request.get(`${HOST_URL}/api/admin/search`, {params: data})
    .then(response=>response.data)
}


// 发布文章
export const publishArticleFn = (data = {}) => {
    return request.post(`${HOST_URL}/api/article/publish`, data).then(response => response.data)
}

// 上传文章封面
export const previewArticlePhotoFn = (data = {}) => {
    return request.post(`${HOST_URL}/api/photo/preview`, data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }).then(response => response.data)
}

// 文章列表
export const listArticleFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/article/items`, { params: data }).then(response => response.data)
}

// 删除文章
export const deleteArticleFn = (data = {}) => {
    return request.post(`${HOST_URL}/api/article/delete`, data).then(response => response.data)
}
// 文章列表（分类）
export const listClassifyArticleFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/article/list`, { params: data }).then(response => response.data)
}

// 关键字搜索文章
export const articleSearchFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/article/search`, { params: data }).then(response => response.data)
}

// 获取所有文章的数量
export const totalArticleFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/article/total`, { params: data }).then(response => response.data)
}

// 获取文章详情
export const articleDetailFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/article/detail`, { params: data }).then(response => response.data)
}

// 宠物管理
// 列表
// /api/pet/list_classify
export const listPetFn = (data = {}) => {
    return request.get(`${HOST_URL}/api/pet/list_classify`, { params: data }).then(response => response.data)
}

// 删除
// /api/pet/remove
export const removePetleFn = (data = {}) => {
    return request.post(`${HOST_URL}/api/pet/remove`, data).then(response => response.data)
}


// 统计整站信息
// /api/visual/total_article
export const total_article = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/total_article`, { params: data }).then(response => response.data)
}
// /api/visual/total_user
export const total_user = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/total_user`, { params: data }).then(response => response.data)
}
// /api/visual/total_pet
export const total_pet = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/total_pet`, { params: data }).then(response => response.data)
}

// /api/classify/list
export const classify_list = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/classify_list`, { params: data }).then(response => response.data)
}

// /api/visual/catetory_data
export const catetory_data = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/catetory_data`, { params: data }).then(response => response.data)
}


// 修改导航图标
// /api/classify/set_icon
export const setClassifyIcon = (data = {}) => {
    return request.post(`${HOST_URL}/api/classify/set_icon`, data).then(response => response.data)
}


// 最近15天发布的宠物信息
// /api/visual/pet_num
export const pet_num = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/pet_num`, { params: data }).then(response => response.data)
}

// 最发布的宠物总数量
// /api/visual/pet_num
export const total_pet_all = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/total_pet_all`, { params: data }).then(response => response.data)
}

// 最发布的宠物总数量
// /api/visual/pet_num
export const total_collect = (data = {}) => {
    return request.get(`${HOST_URL}/api/visual/total_collect`, { params: data }).then(response => response.data)
}








// 假数据
export const fetchData = () => {
    return request({
        url: './mock/table.json',
        method: 'get'
    });
};

export const fetchUserData = () => {
    return request({
        url: './mock/user.json',
        method: 'get'
    });
};

export const fetchRoleData = () => {
    return request({
        url: './mock/role.json',
        method: 'get'
    });
};
